﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using WebNext.UI.Models.Tags;
using System.Collections.Specialized;

namespace WebNext.UI.Utils.ModelBinders
{
	public class TagModelBinder : IModelBinder
	{
		public object BindModel(ControllerContext controllerContext, ModelBindingContext bindingContext)
		{
			if (bindingContext.Model != null)
			{
				throw new NotImplementedException("Cannot update instances");
			}
			return this.BindTagModel(controllerContext.HttpContext.Request.Form);
		}

		private TagViewModel BindTagModel(NameValueCollection form)
		{
			int id = Convert.ToInt32(form["tagid"]);
			string name = form["name"];
			string code = form["code"];
			return new TagViewModel(id, name, code);
		}
	}
}